home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
MacTech 1 to 12
/
MacTech-vol-1-12.toast
/
Tools
/
Alpha 6.51b13 ƒ
/
Tcl
/
Modes
/
latexMacros.tcl
(
.txt
)
< prev
next >
Wrap
LaTeX Document
|
1996-08-15
|
94KB
|
2,681 lines
#############################################################################
#############################################################################
# latexMacros.tcl (called from latex.tcl)
#############################################################################
# Author: Tom Scavo <trscavo@syr.edu>
#############################################################################
#############################################################################
#############################################################################
# Basic Commands
#############################################################################
#--------------------------------------------------------------------------
# Goto:
#--------------------------------------------------------------------------
# Switch to (but don't execute) any of the following applications.
proc latex {} {
global texSig texAppSig
set supportedApps [array names texAppSig]
foreach app $supportedApps { lappend sigs $texAppSig($app) }
set longPrompt "Please locate your TeX app."
if { [catch {launchBackApplSigs $sigs texSig $longPrompt} appname] } {
error "bug in 'launchBackApplSigs'"
set quotedSig "'[string trim $texSig {'}]'"
switchTo $quotedSig
proc bibtex {} {
global bibtexSig bibtexAppSig
set supportedApps [array names bibtexAppSig]
foreach app $supportedApps { lappend sigs $bibtexAppSig($app) }
set longPrompt "Please locate your BibTeX app."
if { [catch {launchBackApplSigs $sigs bibtexSig $longPrompt} appname] } {
error "bug in 'launchBackApplSigs'"
set quotedSig "'[string trim $bibtexSig {'}]'"
switchTo $quotedSig
proc makeindex {} {
global makeindexSig makeindexAppSig
set supportedApps [array names makeindexAppSig]
foreach app $supportedApps { lappend sigs $makeindexAppSig($app) }
set longPrompt "Please locate your MakeIndex app."
if { [catch {launchBackApplSigs $sigs makeindexSig $longPrompt} appname] } {
error "bug in 'launchBackApplSigs'"
set quotedSig "'[string trim $makeindexSig {'}]'"
switchTo $quotedSig
# Find the next or previous environment. Search forward (or backward,
# depending on $forward) for either \begin or \end. If \begin is found,
# search forward for corresponding \end; otherwise, search backward for
# corresponding \begin. Select the found environment, or display an
# error message if no environment is found.
proc findEnvironment {forward} {
set searchString1 {^[ \t]*\\begin\{[^\{\}]*\}|\\end\{[^\{\}]*\}[ \t]*\r?}
set searchPos [getPos]
if { [isSelection] } then {
if { $forward } then {
set searchPos [selEnd]
} else {
set searchPos [expr $searchPos - 1]
} else {
if { $forward } then {
set searchPos [expr $searchPos + 1]
} else {
set searchPos [expr $searchPos - 1]
set searchResult [search -s -f $forward -r 1 -n $searchString1 $searchPos]
if {[string length $searchResult]} then {
set begPos [lindex $searchResult 0]
set endPos [lindex $searchResult 1]
set searchText [getText $begPos $endPos]
regexp {\{(.*)\}} $searchText dummy envName
if {[string match {*begin*} $searchText]} {
set begEnv $begPos
append searchString2 {\\end\{} $envName {\}[ \t]*\r?}
set searchPos $endPos
set searchResult [search -s -f 1 -r 1 -n $searchString2 $searchPos]
if {[string length $searchResult]} {
set endPos [lindex $searchResult 1]
return [list $begPos $endPos]
} else {
return "matching \\end not found"
} else {
set endEnv $endPos
append searchString2 {^[ \t]*\\begin\{} $envName {\}}
set searchPos $begPos
set searchResult [search -s -f 0 -r 1 -n $searchString2 $searchPos]
if {[string length $searchResult]} {
set begPos [lindex $searchResult 0]
return [list $begPos $endPos]
} else {
return "matching \\begin not found"
} else {
if { $forward } then {
return "next environment not found"
} else {
return "previous environment not found"
proc prevEnvironment {} {
global searchNoisily
set findResult [findEnvironment 0]
if {[llength $findResult] == 2} then {
goto [lindex $findResult 0]
} else {
if {$searchNoisily} {beep}
message $findResult
proc nextEnvironment {} {
global searchNoisily
set findResult [findEnvironment 1]
if {[llength $findResult] == 2} then {
goto [lindex $findResult 0]
} else {
if {$searchNoisily} {beep}
message $findResult
proc prevEnvironmentSelect {} {
global searchNoisily
set forward 0
set findResult [findEnvironment $forward]
if {[llength $findResult] == 2} then {
set endPos [lindex $findResult 1]
# if { [regexp {\r} [lookAt [expr $endPos + 1]]] } then {
# set endPos [expr $endPos + 1]
# }
select [lindex $findResult 0] $endPos
} else {
if { $searchNoisily } {beep}
message $findResult
proc nextEnvironmentSelect {} {
global searchNoisily
set forward 1
set findResult [findEnvironment $forward]
if {[llength $findResult] == 2} then {
set endPos [lindex $findResult 1]
# if { [regexp {\r} [lookAt [expr $endPos + 1]]] } then {
# set endPos [expr $endPos + 1]
# }
select [lindex $findResult 0] $endPos
} else {
if { $searchNoisily } {beep}
message $findResult
# Find a LaTeX command in either direction. It's up to the calling
# procedure to pass the correct starting position of the search.
proc findCommand {pos direction} {
# Handle "\ " and "\[" separately:
set searchString {(\\([^a-zA-Z\t\r* []|[a-zA-Z]+)\*?)|([^\\]\\\ )|([^\\]\\\[)}
set searchResult [search -s -f $direction -r 1 -n $searchString $pos]
if { [string length $searchResult] } {
set begPos [lindex $searchResult 0]
set endPos [lindex $searchResult 1]
set lastChar [lookAt [expr $endPos - 1]]
if {$lastChar == "\ " || $lastChar == "\["} then {
return [list [expr $begPos + 1] $endPos]
} else {}
return $searchResult
# Handles everything but "\ " and "\[":
# set searchString {\\([^a-zA-Z\t\r* []|[a-zA-Z]+)\*?}
# return [search -s -f $direction -r 1 -n $searchString $pos]
# Find and goto the beginning of the previous LaTeX command.
proc prevCommand {} {
global searchNoisily
set pos [getPos]
if {$pos > 0} then {
set searchResult [findCommand [expr $pos - 1] 0]
if { [string length $searchResult] } {
goto [lindex $searchResult 0]
return
} else {}
if { $searchNoisily } {beep}
message "previous command not found"
# Find and goto the beginning of the next LaTeX command.
proc nextCommand {} {
global searchNoisily
set pos [getPos]
if {$pos < [maxPos]} then {
set searchResult [findCommand [expr $pos + 1] 1]
if { [string length $searchResult] } {
goto [lindex $searchResult 0]
return
} else {}
if { $searchNoisily } {beep}
message "next command not found"
# Select the previous LaTeX command, but do not attempt to select
# any associated argument.
proc prevCommandSelect {} {
global searchNoisily
set pos [getPos]
if {$pos > 0} then {
set searchResult [findCommand [expr $pos - 1] 0]
if { [string length $searchResult] } {
eval select $searchResult
return
} else {}
if { $searchNoisily } {beep}
message "previous command not found"
# Select the next LaTeX command, but do not attempt to select
# any associated argument.
proc nextCommandSelect {} {
global searchNoisily
set pos [getPos]
if {$pos < [maxPos]} then {
if { [isSelection] } then {
set pos [expr $pos + 1]
set searchResult [findCommand $pos 1]
if { [string length $searchResult] } {
eval select $searchResult
return
} else {}
if { $searchNoisily } {beep}
message "next command not found"
# Find a LaTeX command with arguments in either direction. It's up
# to the calling procedure to pass the starting position of the search.
# (Handles everything but "\ " and commands whose arguments contain
# embedded braces.)
proc findCommandWithArgs {pos direction} {
set searchString {\\([^a-zA-Z\t\r]|[a-zA-Z]+\*?)(\[.*\])*({[^{}]*})*}
return [search -s -f $direction -r 1 -n $searchString $pos]
# Select the previous LaTeX command and any associated arguments.
proc prevCommandSelectWithArgs {} {
global searchNoisily
set pos [getPos]
if {$pos > 0} then {
set searchResult [findCommandWithArgs [expr $pos - 1] 0]
if { [string length $searchResult] } {
eval select $searchResult
return
} else {}
if { $searchNoisily } {beep}
message "previous command not found"
# Select the next LaTeX command and any associated arguments.
proc nextCommandSelectWithArgs {} {
global searchNoisily
set pos [getPos]
if {$pos < [maxPos]} then {
if { [isSelection] } then {
set pos [expr $pos + 1]
set searchResult [findCommandWithArgs $pos 1]
if { [string length $searchResult] } {
eval select $searchResult
return
} else {}
if { $searchNoisily } {beep}
message "next command not found"
# Find a LaTeX sectioning command in either direction. It's up to
# the calling procedure to pass the starting position of the search.
proc findSection {pos direction} {
global funcExprAlt
return [search -s -f $direction -r 1 -n $funcExprAlt $pos]
# Select the previous LaTeX sectioning command.
proc prevSection {} {
global searchNoisily
set pos [getPos]
if {$pos > 0} then {
set searchResult [findSection [expr $pos - 1] 0]
if { [string length $searchResult] } {
eval select $searchResult
return
} else {}
if { $searchNoisily } {beep}
message {previous section not found}
# Select the next LaTeX sectioning command.
proc nextSection {} {
global searchNoisily
set pos [getPos]
if {$pos < [maxPos]} then {
if { [isSelection] } then {
set pos [expr $pos + 1]
set searchResult [findSection $pos 1]
if { [string length $searchResult] } {
eval select $searchResult
return
} else {}
if { $searchNoisily } {beep}
message {next section not found}
proc prevSectionSelect {} {
global searchNoisily
set pos [getPos]
if {$pos > 0} then {
set searchResult [findSection [expr $pos - 1] 0]
if { [string length $searchResult] } {
set begPos [lindex $searchResult 0]
set searchPos [expr [lindex $searchResult 1] + 1]
set searchResult [findSection $searchPos 1]
if { [string length $searchResult] } {
set endPos [lindex $searchResult 0]
} else {
set searchResult [search -s -f 1 -r 0 -n "\\end{document}" $searchPos]
set endPos [lindex $searchResult 0]
select $begPos $endPos
return
} else {}
if { $searchNoisily } {beep}
message {previous section not found}
# Select the next LaTeX sectioning command.
proc nextSectionSelect {} {
global searchNoisily
set pos [getPos]
if {$pos < [maxPos]} then {
if { [isSelection] } then {
set pos [expr $pos + 1]
set searchResult [findSection $pos 1]
if { [string length $searchResult] } {
set begPos [lindex $searchResult 0]
set searchPos [expr [lindex $searchResult 1] + 1]
set searchResult [findSection $searchPos 1]
if { [string length $searchResult] } {
set endPos [lindex $searchResult 0]
} else {
set searchResult [search -s -f 1 -r 0 -n "\\end{document}" $searchPos]
set endPos [lindex $searchResult 0]
select $begPos $endPos
return
} else {}
if { $searchNoisily } {beep}
message {next section not found}
# Find a LaTeX subsectioning command in either direction. It's up to
# the calling procedure to pass the starting position of the search.
proc findSubsection {pos direction} {
global funcExpr
return [search -s -f $direction -r 1 -n $funcExpr $pos]
proc prevSubsection {} {
global searchNoisily
set pos [getPos]
if {$pos > 0} then {
set searchResult [findSubsection [expr $pos - 1] 0]
if { [string length $searchResult] } {
eval select $searchResult
return
} else {}
if { $searchNoisily } {beep}
message {previous (sub)*section not found}
# Select the next LaTeX sectioning command.
proc nextSubsection {} {
global searchNoisily
set pos [getPos]
if {$pos < [maxPos]} then {
if { [isSelection] } then {
set pos [expr $pos + 1]
set searchResult [findSubsection $pos 1]
if { [string length $searchResult] } {
eval select $searchResult
return
} else {}
if { $searchNoisily } {beep}
message {next (sub)*section not found}
proc prevSubsectionSelect {} {
global searchNoisily
set pos [getPos]
if {$pos > 0} then {
set searchResult [findSubsection [expr $pos - 1] 0]
if { [string length $searchResult] } {
set begPos [lindex $searchResult 0]
set endPos [lindex $searchResult 1]
set searchPos [expr $endPos + 1]
set commandName [extractCommandName [getText $begPos $endPos]]
if {[string match {section*} $commandName]} then {
set searchResult [findSection $searchPos 1]
} else {
set searchResult [findSubsection $searchPos 1]
if { [string length $searchResult] } {
set endPos [lindex $searchResult 0]
} else {
set searchResult [search -s -f 1 -r 0 -n "\\end{document}" $searchPos]
set endPos [lindex $searchResult 0]
select $begPos $endPos
return
} else {}
if { $searchNoisily } {beep}
message {previous (sub)*section not found}
# Select the next LaTeX sectioning command.
proc nextSubsectionSelect {} {
global searchNoisily
set pos [getPos]
if {$pos < [maxPos]} then {
if { [isSelection] } then {
set pos [expr $pos + 1]
set searchResult [findSubsection $pos 1]
if { [string length $searchResult] } {
set begPos [lindex $searchResult 0]
set endPos [lindex $searchResult 1]
set searchPos [expr $endPos + 1]
set commandName [extractCommandName [getText $begPos $endPos]]
if {[string match {section*} $commandName]} then {
set searchResult [findSection $searchPos 1]
} else {
set searchResult [findSubsection $searchPos 1]
if { [string length $searchResult] } {
set endPos [lindex $searchResult 0]
} else {
set searchResult [search -s -f 1 -r 0 -n "\\end{document}" $searchPos]
set endPos [lindex $searchResult 0]
select $begPos $endPos
return
} else {}
if { $searchNoisily } {beep}
message {next (sub)*section not found}
proc gotoTabStop {dirIndicator} {
set pos [getPos]
if {$dirIndicator} then {
if {$pos == [maxPos]} { return 0 }
} else {
if {$pos == 0} { return 0 }
# Fixes a bug in 'search':
set pos [expr $pos - 1]
set searchResult [search -s -n -f $dirIndicator -m 0 -i 1 -r 0 {
} $pos]
if {[string length $searchResult]} then {
goto [lindex $searchResult 0]
return 1
} else {
return 0
proc nextTabStop {} {
global searchNoisily
set forward 1
if { [gotoTabStop $forward] } then {
deleteChar
} else {
if { $searchNoisily } {beep}
message "tab stop not found"
proc prevTabStop {} {
global searchNoisily
set forward 0
if { [gotoTabStop $forward] } then {
deleteChar
} else {
if { $searchNoisily } {beep}
message "tab stop not found"
# Goto the nth tab stop. A nonzero argument is non-interactive
# (for use in Tcl procs) and not validated.
proc nthTabStop {{numTabStops 0}} {
global searchNoisily promptNoisily useStatusBar
if { $numTabStops == 0 } then {
if { $promptNoisily && $useStatusBar } { beep }
catch {sPrompt "How many tab stops?" "3"} numTabStops
if { $numTabStops == "cancel" || $numTabStops == 0 } then {
return
} elseif { ![isInteger $numTabStops] } then {
beep
message "invalid input: integer required"
return
set currentPos [getPos]
if { $numTabStops > 0 } { set forward 1 } { set forward 0 }
set maxits [expr abs($numTabStops)]
if { ![gotoTabStop $forward] } then {
if { $searchNoisily } {beep}
message "tab stop not found"
goto $currentPos
return
for { set i 1 } { $i < $maxits } { incr i } {
if { $forward } { forwardChar } { backwardChar }
if { ![gotoTabStop $forward] } then {
if { $searchNoisily } { beep }
message "tab stop not found"
goto $currentPos
return
deleteChar
#--------------------------------------------------------------------------
# Utilities:
#--------------------------------------------------------------------------
# A keyboard-bound method of accessing menu commands. Takes a list of
# menu items (i.e., the tail of a 'menu' command), the menu name (the
# argument of the '-n' switch) , and the name of a menu filter (the
# argument of the '-p' switch) as input, and displays these items in a
# list box. If the chosen item is a menu command (as opposed to a
# submenu), it is passed to the menu filter; otherwise, 'chooseCommand'
# recursively calls itself until a menu command is chosen or the cancel
# button is pressed.
proc chooseCommand {menuItems {menuName ""} {menuFilterProc ""} {level 1}} {
watchCursor
if { $menuItems == "" } { return }
# Preprocess the list of menu items:
foreach item $menuItems {
regsub -all {[<!/].} $item {} item
regsub -all {
} $item {} item
lappend menOut $item
if { [string match "menu*" $item] } {
if { [set ind [lsearch $item {-n}]] >= 0 } {
lappend top "[lindex $item [incr ind]]:"
} elseif { ![string match "(*" $item] } {
lappend top $item
# Present the menu items to the user:
set res [listpick -p "Choose menu command (level $level):" $top]
# Either execute a command or recurse on a submenu:
if { [lsearch $menOut $res] >= 0 } {
# Execute the command via the menu filter, if necessary:
if { $menuFilterProc == "" } {
$res
} else {
$menuFilterProc $menuName $res
} else {
set res [string trimright $res {:}]
foreach item $menOut {
if { [lsearch $item $res] >= 0 } {
set menuItems [lindex $item end]
# Determine the name of this submenu:
if { [set ind [lsearch $item {-n}]] >= 0 } {
set menuName [lindex $item [incr ind]]
} else {
set menuName ""
}
# Determine the name of the menu filter for this submenu:
if { [set ind [lsearch $item {-p}]] >= 0 } {
set menuFilterProc [lindex $item [incr ind]]
} else {
set menuFilterProc ""
}
return [chooseCommand $menuItems $menuName $menuFilterProc [incr level]]
proc insertLiteralTab {} {
if {[isSelection]} then {
deleteSelection
insertText "\t"
proc insertTabStop {} {
if {[isSelection]} then {
deleteSelection
insertText "
# Removes all tab stops from the current selection (if there is one)
# or the current document, maintaining the cursor position in the
# latter case.
proc deleteTabStops {} {
global searchNoisily
watchCursor
set subs1 0; set subs2 0; set subs3 0
set pos [getPos]
if {[set start $pos] == [set end [selEnd]]} {
set messageString "document"
set start 0
set end [maxPos]
set text1 [getText $start $pos]
set subs1 [regsub -all {
} $text1 {} text1]
set text2 [getText $pos $end]
set subs2 [regsub -all {
} $text2 {} text2]
append text $text1 $text2
} else {
set messageString "selection"
set text [getText $start $end]
set subs3 [regsub -all {
} $text {} text]
if {$subs1 || $subs2 || $subs3} then {
replaceText $start $end $text
if {$messageString == "document"} then {
goto [expr $pos - $subs1]
} else {
set end [getPos]
select $start $end
set subs [expr $subs1 + $subs2 + $subs3]
message "$subs tab stops removed from $messageString"
} else {
if {$searchNoisily} {beep}
message "no tab stops found in $messageString"
# Delete all unnecessary comments from the current document:
proc deleteComments {} {
switch [askyesno "Warning! This operation can not be undone. \
Continue anyway?"] {
"yes" {}
"no" { return }
replaceString {}
eval select [search -f 1 -r 1 -i 1 -m 0 -- {^[ \t]*%.*\r} 0]
replaceAll
replaceString {}
eval select [search -f 1 -r 1 -i 1 -m 0 -- {[ \t]+%.*} 0]
replaceAll
replaceString {\1%}
eval select [search -f 1 -r 1 -i 1 -m 0 -- {([^\\](\\\\)*)%.*} 0]
replaceAll
# Converts all straight quotes to their TeX equivalents.
proc convertQuotes {} {
global searchNoisily
message "working
watchCursor
set messageString "selection"
if {[set start [getPos]] == [set end [selEnd]]} {
set messageString "document"
set start 0
set end [maxPos]
set text [getText $start $end]
# Convert all left double quotes:
set convert1 [regsub -all "\(\^\|\[\ \r\t\(\[\{\]\)\"" $text {\1``} text]
# Convert all right double quotes:
set convert2 [regsub -all "\(\[\^\\\\\]\)\"" $text {\1''} text]
# Convert all left single quotes:
set convert3 [regsub -all "\(\^\|\[\ \r\t\(\[\{\]\)\'" $text {\1`} text]
if {$convert1 || $convert2 || $convert3} then {
replaceText $start $end $text
message "all quotes in $messageString converted"
} else {
if {$searchNoisily} {beep}
message "no quotes found in $messageString"
# Returns true if the argument contains non-literal double dollar
# signs, and false otherwise.
proc containsDoubleDollarSigns {text} {
return [regexp {(^|[^\\])\$\$} $text]
# Converts all $$...$$ pairs to \[...\] and returns the number of such
# pairs converted. If the dollar signs are unbalanced, does nothing
# and returns -1.
proc convertDoubleDollarSigns {} {
watchCursor
set messageString "selection"
if {[set start [getPos]] == [set end [selEnd]]} {
set messageString "document"
set start 0
set end [maxPos]
set text [getText $start $end]
set subs [regsub -all {(^|[^\\])\$\$([^$]*)\$\$} $text {\1\\[\2\\]} text]
if {[containsDoubleDollarSigns $text]} then {return -1}
if {$subs} then {
replaceText $start $end $text
return [expr $subs]
# Returns true if the argument contains a non-literal dollar sign,
# and false otherwise.
proc containsSingleDollarSign {text} {
return [regexp {(^|[^\\])\$} $text]
# Converts all $...$ pairs to \(...\), maintains the cursor position,
# and returns the number of such pairs converted. If the dollar signs
# are unbalanced, does nothing and returns -1.
proc convertSingleDollarSigns {} {
watchCursor
set subs1 0; set subs2 0; set subs3 0
set pos [getPos]; set pos2 $pos
if {[set start $pos] == [set end [selEnd]]} {
set isSelection 0
set start 0
set end [maxPos]
set text1 [getText $start $pos]
set subs1 [regsub -all {(^|[^\\])\$([^$]*)\$} $text1 {\1\\(\2\\)} text1]
# Is there a dollar sign left over? If so, search backward for this
# dollar sign and prepare to do a substitution on the text to the right
# of this dollar sign.
if {[containsSingleDollarSign $text1]} then {
set searchString {[^\\]\$}
set searchResult [search -s -n -f 0 -m 0 -i 1 -r 1 $searchString [expr $pos-1]]
set pos2 [lindex $searchResult 0]
set text1 [string range $text1 0 [expr $pos2 + (2 * $subs1)]]
set pos [expr $pos + 2]
set text2 [getText $pos2 $end]
set subs2 [regsub -all {(^|[^\\])\$([^$]*)\$} $text2 {\1\\(\2\\)} text2]
# Is there a dollar sign left over? If so, it's unbalanced.
if {[containsSingleDollarSign $text2]} then {return -1}
append text $text1 $text2
} else {
set isSelection 1
set text [getText $start $end]
set subs3 [regsub -all {(^|[^\\])\$([^$]*)\$} $text {\1\\(\2\\)} text]
# Is there a dollar sign left over? If so, it's unbalanced.
if {[containsSingleDollarSign $text]} then {return -1}
if {$subs1 || $subs2 || $subs3} then {
replaceText $start $end $text
# If there is a selection, just put it back. Otherwise, adjust the
# cursor position based on the number of substitutions.
if {$isSelection} then {
set end [getPos]
select $start $end
} else {
goto [expr $pos + (2 * $subs1)]
return [expr $subs1 + $subs2 + $subs3]
proc convertDollarSigns {} {
global searchNoisily
if {[isSelection]} then {
set messageString "selection"
} else {
set messageString "document"
set subs2 [convertDoubleDollarSigns]
if {$subs2 == -1} then {
beep
alertnote "unmatched double dollar signs in $messageString"
} else {
set subs1 [convertSingleDollarSigns]
if {$subs1 == -1} then {
beep
alertnote "unmatched single dollar sign in $messageString"
} elseif {$subs1 == 0 && $subs2 == 0} then {
if {$searchNoisily} {beep}
message "no dollar signs found in $messageString"
} else {
message "$subs1 pairs of \$
\$ and $subs2 pairs of \$\$
\$\$ removed from $messageString"
#############################################################################
# Paragraph Mode Macros
#############################################################################
#--------------------------------------------------------------------------
# Documents:
#--------------------------------------------------------------------------
proc newLaTeXDocument {} {
catch {prompt "Choose a documentclass:" "article" "" "article" \
"report" "book" "letter" "slides"} documentType
if {$documentType != "cancel"} then {
new
newMode TeX
if { [catch {${documentType}Documentclass}] } then {
wrapDocument "$documentType"
while { [options] } {}
nextTabStop
message "enter option (or leave blank)"
proc letterDocumentclass {} {
set preamble "\r\\address\{%\r"
append preamble "
\\\\ % insert your name here\r"
append preamble "
\\\\ % insert your address here\r"
append preamble "
\\\\ % insert more address here\r"
append preamble "
% insert city-state-zip here\r"
append preamble "\}\r\r"
append preamble "\\date\{
\} % optional\r"
append preamble "\\signature\{
\}\r\r"
set body "\r\\begin\{letter\}\{%\r"
append body "
\\\\ % insert addressee's name here\r"
append body "
\\\\ % insert addressee's address here\r"
append body "
\\\\ % insert more address here\r"
append body "
% insert addressee's city-state-zip here\r"
append body "\}\r\r"
append body "\\opening\{Dear
,\}\r\r"
if {[isEmptyFile]} then {
append body "% BODY OF LETTER\r"
append body "
\r\r"
} else {
if {[isDocumentSelected]} then {
set text [getSelect]
# deleteText 0 [maxPos]
append body "$text\r"
} else {
alertnote "nonempty file: delete text or \'Select All\'\
from the Edit menu"
return
append body "\\closing\{Sincerely,\}\r\r"
append body "\\encl\{
\}\r"
append body "\\cc\{
\}\r\r"
append body "\\end\{letter\}\r\r"
insertDocument "letter" $preamble $body
nextTabStop
message "enter option (or leave blank)"
proc articleDocumentclass {} {
if { [wrapDocument "article"] } {
nextTabStop
message "enter option (or leave blank)"
proc reportDocumentclass {} {
if { [wrapDocument "report"] } {
nextTabStop
message "enter option (or leave blank)"
proc bookDocumentclass {} {
if { [wrapDocument "book"] } {
nextTabStop
message "enter option (or leave blank)"
proc slidesDocumentclass {} {
if { [wrapDocument "slides"] } {
nextTabStop
message "enter option (or leave blank)"
proc otherDocumentclass {} {
catch {prompt "What documentclass?" "article"} documentType
if {$documentType != "cancel"} then {
if { [wrapDocument "$documentType"] } {
nextTabStop
message "enter option (or leave blank)"
# If an option is inserted, return true; otherwise, return false.
proc options {} {
set option [getOption]
if {$option != ""} then {
insertOption $option
return 1
return 0
proc getOption {} {
catch {prompt "Choose an option:" "11pt" "" "10pt" "11pt" "12pt" "(-" \
"letterpaper" "legalpaper" "executivepaper" "a4paper" "a5paper" \
"b5paper" "(-" "landscape" "(-" "final" "draft" "(-" \
"oneside" "twoside" "(-" "openright" "openany" "(-" \
"onecolumn" "twocolumn" "(-" "notitlepage" "titlepage" \
"openbib" "(-" "leqno" "(-" "fleqn"} optionName
if {$optionName != "cancel"} then {
return $optionName
} else {
return ""
proc insertOption {option} {
global TeXmodeVars
set searchString {\\documentclass}
set searchResult [search -s -n -f 1 -m 0 -i 1 -r 1 $searchString 0]
if {[llength $searchResult] == 0} then {
if { $TeXmodeVars(searchNoisily) } {beep}
message "can\'t find \\documentclass"
} else {
set nextCharPos [lindex $searchResult 1]
goto $nextCharPos
set nextChar [lookAt $nextCharPos]
if {$nextChar == "\["} then {
forwardChar
insertText $option
if {[lookAt [getPos]] != "\]"} then {
insertText ","
} elseif {$nextChar == "\{"} then {
insertText "\[$option\]"
} else {
alertnote "unrecognizable \\documentclass statement"
proc insertPackage {package} {
global TeXmodeVars
# Check to see if $package is already loaded:
if { $package != "" } then {
# append searchString {\\usepackage\{.*} $package {.*\}}
append searchString {^[^%]*\\usepackage\{.*} $package {.*\}}
set searchResult [search -s -n -f 1 -m 0 -i 1 -r 1 $searchString 0]
if {[llength $searchResult] != 0} then {
if { $TeXmodeVars(searchNoisily) } {beep}
message "$package package already loaded"
return
# Newlines are allowed in the arguments of \documentclass:
set searchString {\\documentclass(\[[^][]*\])?{[^{}]*}}
# Search for \documentclass command:
set searchResult [search -s -n -f 1 -m 0 -i 1 -r 1 $searchString 0]
if {[llength $searchResult] == 0} then {
if { $TeXmodeVars(searchNoisily) } {beep}
message "can't find \\documentclass"
} else {
pushMark
goto [lindex $searchResult 1]
set txt "\r\\usepackage\{$package\}"
insertText $txt
backwardChar
message "Press <Ctl .> to return to previous position"
proc filecontents {} {
global searchNoisily
set searchString {\\documentclass}
set searchResult [search -s -n -f 1 -m 0 -i 1 -r 1 $searchString 0]
if {[llength $searchResult] == 0} then {
if {$searchNoisily} {beep}
message "can\'t find \\documentclass"
return
} else {
set prompt "File to be included:"
if {[catch {getfile $prompt} path]} then {
return
} else {
replaceText 0 0 [buildFilecontents $path]
goto 0
message "file included"
proc filecontentsAll {} {
global searchNoisily
watchCursor
message "locating all input files
set currentWin [lindex [winNames -f] 0]
# Is the current window part of TeX fileset?
set fset [isWindowInFileset $currentWin "tex"]
if { $fset == "" } {
set searchString {\\documentclass}
set searchResult [search -s -n -f 1 -m 0 -i 1 -r 1 $searchString 0]
if {[llength $searchResult] == 0} then {
if {$searchNoisily} {beep}
message "can\'t find \\documentclass"
return
} else {
set text [getText 0 [maxPos]]
} else {
# Will not handle a base file that is open and dirty:
set text [buildFilecontents [texFilesetBaseName $fset]]
set currentDir [file dirname $currentWin]
set newText [texResolveAll $text $currentDir]
if { [string length $text] == [string length $newText] } then {
beep
message "no files to include"
} else {
replaceText 0 [maxPos] $newText
goto 0
message "all files included"
# Takes a LaTeX document string and a path as input, and returns
# a modified document string with all filecontents environments
# prepended.
proc texResolveAll {latexDoc currentDir} {
global TeXmodeVars
set pairs [list \
{{\\documentclass} {.cls}} {{\\LoadClass} {.cls}} \
{{\\include} {.tex}} \
{{\\usepackage} {.sty}} {{\\RequirePackage} {.sty}} \
{{\\input} {}} \
{{\\bibliography} {.bib}} {{\\bibliographystyle} {.bst}} \
]
foreach macro $TeXmodeVars(boxMacroNames) {
regsub {\*} $macro {\\*} macro
lappend pairs [list \\\\$macro {}]
foreach pair $pairs {
set cmd [car $pair]
set ext [cadr $pair]
set searchString $cmd
append searchString {(\[[^][]*\])?{([^{}]*)}}
set searchText $latexDoc
while { [regexp -indices $searchString $searchText mtch dummy theArgs] } {
set begPos [lindex $theArgs 0]
set endPos [lindex $theArgs 1]
set args [string range $searchText $begPos $endPos]
foreach arg [split $args ,] {
if { $cmd == {\\input} && ![string length [file extension $arg]] } {
set ext {.tex}
}
set files [glob -nocomplain $currentDir:$arg*]
set filename "$currentDir:$arg$ext"
if { [lsearch -exact $files $filename] > -1 } {
set tempDoc $latexDoc
set latexDoc [buildFilecontents $filename]
append latexDoc $tempDoc
}
set searchText [string range $searchText [expr $endPos + 2] end]
return $latexDoc
# Takes a filename as input and returns a filecontents environment
# based on the contents of that file. If a second argument is given,
# use that as the argument of the filecontents environment instead
# of the original filename.
proc buildFilecontents {filename {newFilename {}}} {
set text [readFile $filename]
# Fix end-of-line characters:
regsub -all "\xa" $text "\xd" text
set envName "filecontents"
if { $newFilename == {} } {
set envArg "{[file tail $filename]}"
} else {
set envArg "{$newFilename}"
return [buildEnvironment $envName $envArg "$text\r" "\r\r"]
#--------------------------------------------------------------------------
# Page Layout:
#--------------------------------------------------------------------------
proc maketitle {} {
global searchNoisily
set searchString {\\document(class|style)(\[.*\])?\{.*\}}
set searchResult [search -s -n -f 1 -m 0 -i 1 -r 1 $searchString 0]
if {[llength $searchResult] == 0} then {
if {$searchNoisily} {beep}
message "can\'t find \\documentclass or \\documentstyle"
} else {
set searchPos [lindex $searchResult 1]
set searchString {\\begin\{document\}}
set searchResult [search -s -n -f 1 -m 0 -i 1 -r 1 $searchString $searchPos]
if {[llength $searchResult] == 0} then {
if {$searchNoisily} {beep}
message "can\'t find \\begin\{document\}"
} else {
goto [lindex $searchResult 1]
set currentPos [getPos]
set txt "\r\r% Definition of title page:"
append txt "\r\\title\{"
append txt "\r\t
\r\}"
append txt "\r\\author\{"
append txt "\r\t
\t% insert author(s) here"
append txt "\r\}"
append txt "\r\\date\{
\}\t% optional"
append txt "\r\r\\maketitle"
insertText $txt
goto $currentPos
nextTabStop
message "insert title"
proc abstract {} { doWrapEnvironment "abstract" }
proc titlepage {} { doWrapEnvironment "titlepage" }
proc getPagestyle {} {
catch {prompt "Choose a pagestyle:" "plain" "" "plain" "empty" \
"headings" "myheadings"} pagestyleName
if {$pagestyleName != "cancel"} then {
return $pagestyleName
} else {
return ""
proc pagestyle {} {
set pagestyleName [getPagestyle]
if {$pagestyleName != ""} then {
openingCarriageReturn
insertObject "\\pagestyle\{$pagestyleName\}"
closingCarriageReturn
proc thispagestyle {} {
set pagestyleName [getPagestyle]
if {$pagestyleName != ""} then {
openingCarriageReturn
insertObject "\\thispagestyle\{$pagestyleName\}"
closingCarriageReturn
proc getPagenumberingStyle {} {
catch {prompt "Choose a pagenumbering style:" "arabic" "" "arabic" \
"roman" "Roman" "alph" "Alph"} pagenumberingStyle
if {$pagenumberingStyle != "cancel"} then {
return $pagenumberingStyle
} else {
return ""
proc pagenumbering {} {
set pagenumberingStyle [getPagenumberingStyle]
if {$pagenumberingStyle != ""} then {
openingCarriageReturn
insertObject "\\pagenumbering\{$pagenumberingStyle\}"
closingCarriageReturn
proc twocolumn {} {
openingCarriageReturn
insertObject "\\twocolumn"
closingCarriageReturn
proc onecolumn {} {
openingCarriageReturn
insertObject "\\onecolumn"
closingCarriageReturn
#--------------------------------------------------------------------------
# Sectioning:
#--------------------------------------------------------------------------
proc part {} {
if {[wrapObject "\\part{" "}
"]} then {
message "don't forget the label"
} else {
message "type the part name and don't forget the label"
proc chapter {} {
if {[wrapObject "\\chapter{" "}
"]} then {
message "don't forget the label"
} else {
message "type the chapter name and don't forget the label"
proc section {} {
if {[wrapObject "\\section{" "}
"]} then {
message "don't forget the label"
} else {
message "type the section name and don't forget the label"
proc subsection {} {
if {[wrapObject "\\subsection{" "}
"]} then {
message "don't forget the label"
} else {
message "type the subsection name and don't forget the label"
proc subsubsection {} {
if {[wrapObject "\\subsubsection{" "}
"]} then {
message "don't forget the label"
} else {
message "type the subsubsection name and don't forget the label"
proc paragraph {} {
if {[wrapObject "\\paragraph{" "}
"]} then {
message "don't forget the label"
} else {
message "type the paragraph name and don't forget the label"
proc subparagraph {} {
if {[wrapObject "\\subparagraph{" "}
"]} then {
message "don't forget the label"
} else {
message "type the subparagraph name and don't forget the label"
proc appendix {} {insertObject "\\appendix"}
#--------------------------------------------------------------------------
# Text Style:
#--------------------------------------------------------------------------
proc emph {} {
if {[wrapObject "\\emph{" "}
"]} then {
message "selected text has been emphasized"
} else {
message "enter text to be emphasized"
proc textup {} {
if {[wrapObject "\\textup{" "}
"]} then {
message "selected text has upright shape"
} else {
message "enter text to have upright shape"
proc textit {} {
if {[wrapObject "\\textit{" "}
"]} then {
message "selected text has italic shape"
} else {
message "enter text to have italic shape"
proc textsl {} {
if {[wrapObject "\\textsl{" "}
"]} then {
message "selected text has slanted shape"
} else {
message "enter text to have slanted shape"
proc textsc {} {
if {[wrapObject "\\textsc{" "}
"]} then {
message "selected text has small caps shape"
} else {
message "enter text to have small caps shape"
proc textmd {} {
if {[wrapObject "\\textmd{" "}
"]} then {
message "selected text has been set in medium series"
} else {
message "enter text to be set in medium series"
proc textbf {} {
if {[wrapObject "\\textbf{" "}
"]} then {
message "selected text has been set in bold series"
} else {
message "enter text to be set in bold series"
proc textrm {} {
if {[wrapObject "\\textrm{" "}
"]} then {
message "selected text has been set with roman family"
} else {
message "enter text to be set using roman family"
proc textsf {} {
if {[wrapObject "\\textsf{" "}
"]} then {
message "selected text has been set with sans serif family"
} else {
message "enter text to be set using sans serif family"
proc texttt {} {
if {[wrapObject "\\texttt{" "}
"]} then {
message "selected text has been set with typewriter family"
} else {
message "enter text to be set using typewriter family"
proc textnormal {} {
if {[wrapObject "\\textnormal{" "}
"]} then {
message "selected text has been set with normal style"
} else {
message "enter text to be set using normal style"
proc em {} {
if {[wrapObject "{\\em " "}
"]} then {
message "emphasized text set"
} else {
message "enter text to be emphasized"
proc upshape {} {
if {[wrapObject "{\\upshape " "}
"]} then {
message "text set in upright shape"
} else {
message "enter text to be set in upright shape"
proc itshape {} {
if {[wrapObject "{\\itshape " "}
"]} then {
message "text set in italics shape"
} else {
message "enter text to be set in italics shape"
proc slshape {} {
if {[wrapObject "{\\slshape " "}
"]} then {
message "text set in slanted shape"
} else {
message "enter text to be set in slanted shape"
proc scshape {} {
if {[wrapObject "{\\scshape " "}
"]} then {
message "text set in small caps shape"
} else {
message "enter text to be set in small caps shape"
proc mdseries {} {
if {[wrapObject "{\\mdseries " "}
"]} then {
message "text set in medium series"
} else {
message "enter text to be set in medium series"
proc bfseries {} {
if {[wrapObject "{\\bfseries " "}
"]} then {
message "text set in bold series"
} else {
message "enter text to be set in bold series"
proc rmfamily {} {
if {[wrapObject "{\\rmfamily " "}
"]} then {
message "text set in roman family"
} else {
message "enter text to be set in roman family"
proc sffamily {} {
if {[wrapObject "{\\sffamily " "}
"]} then {
message "text set in sans serif family"
} else {
message "enter text to be set in sans serif family"
proc ttfamily {} {
if {[wrapObject "{\\ttfamily " "}
"]} then {
message "text set in typewriter family"
} else {
message "enter text to be set in typewriter family"
proc normalfont {} {
if {[wrapObject "{\\normalfont " "}
"]} then {
message "text set in normal style"
} else {
message "enter text to be set in normal style"
#--------------------------------------------------------------------------
# Text Size:
#--------------------------------------------------------------------------
proc tiny {} {
if {[wrapObject "{\\tiny " "}
"]} then {
message "tiny text set"
} else {
message "enter tiny text"
proc scriptsize {} {
if {[wrapObject "{\\scriptsize " "}
"]} then {
message "scriptsize text set"
} else {
message "enter scriptsize text"
proc footnotesize {} {
if {[wrapObject "{\\footnotesize " "}
"]} then {
message "footnotesize text set"
} else {
message "enter footnotesize text"
proc small {} {
if {[wrapObject "{\\small " "}
"]} then {
message "small text set"
} else {
message "enter small text"
proc normalsize {} {
if {[wrapObject "{\\normalsize " "}
"]} then {
message "normalsize text set"
} else {
message "enter normalsize text"
proc large {} {
if {[wrapObject "{\\large " "}
"]} then {
message "large text set"
} else {
message "enter large text"
proc Large {} {
if {[wrapObject "{\\Large " "}
"]} then {
message "Large text set"
} else {
message "enter Large text"
proc LARGE {} {
if {[wrapObject "{\\LARGE " "}
"]} then {
message "LARGE text set"
} else {
message "enter LARGE text"
proc huge {} {
if {[wrapObject "{\\huge " "}
"]} then {
message "huge text set"
} else {
message "enter huge text"
proc Huge {} {
if {[wrapObject "{\\Huge " "}
"]} then {
message "Huge text set"
} else {
message "enter Huge text"
#--------------------------------------------------------------------------
# International:
#--------------------------------------------------------------------------
proc {
} {} {
if {[wrapObject "\\`{" "}
"]} then {
message "accent set"
} else {
message "enter single character"
proc {
} {} {
if {[wrapObject "\\'{" "}
"]} then {
message "accent set"
} else {
message "enter single character"
proc {
} {} {
if {[wrapObject "\\^{" "}
"]} then {
message "accent set"
} else {
message "enter single character"
proc {
} {} {
if {[wrapObject "\\\"{" "}
"]} then {
message "accent set"
} else {
message "enter single character"
proc {
} {} {
if {[wrapObject "\\~{" "}
"]} then {
message "accent set"
} else {
message "enter single character"
proc {
} {} {insertObject "\\c\{c\}"}
proc {
} {} {insertObject "\\c\{C\}"}
proc {
} {} {insertObject "\\oe"}
proc {
} {} {insertObject "\\OE"}
proc {
} {} {insertObject "\\ae"}
proc {
} {} {insertObject "\\AE"}
proc {
} {} {insertObject "\\aa"}
proc {
} {} {insertObject "\\AA"}
proc {
} {} {insertObject "\\o"}
proc {
} {} {insertObject "\\O"}
proc {
} {} {insertObject "\\ss"}
proc {
} {} {insertObject "?`"}
proc {
} {} {insertObject "!`"}
#--------------------------------------------------------------------------
# Environments:
#--------------------------------------------------------------------------
proc enumerate {} {
global promptNoisily useStatusBar
set envName "enumerate"
if {$promptNoisily && $useStatusBar} {beep}
catch {sPrompt "$envName: how many items?" 3} numberItems
if {$numberItems == "cancel"} then {
return
} elseif {![isPositiveInteger $numberItems]} then {
beep
message "invalid input: unsigned, postive integer required"
return
if {$numberItems} then {
set body "\t\\item
for {set i 1} {$i < $numberItems} {incr i} {
append body "\r\r\t\\item
append body "\r"
} else {
set body "\t
if {[insertEnvironment $envName "" $body]} then {
nextTabStop
message "type first item"
proc itemize {} {
global promptNoisily useStatusBar
set envName "itemize"
if {$promptNoisily && $useStatusBar} {beep}
catch {sPrompt "$envName: how many items?" 3} numberItems
if {$numberItems == "cancel"} then {
return
} elseif {![isPositiveInteger $numberItems]} then {
beep
message "invalid input: unsigned, postive integer required"
return
if {$numberItems} then {
set body "\t\\item
for {set i 1} {$i < $numberItems} {incr i} {
append body "\r\r\t\\item
append body "\r"
} else {
set body "\t
if {[insertEnvironment $envName "" $body]} then {
nextTabStop
message "type first item"
proc description {} {
global promptNoisily useStatusBar
set envName "description"
if {$promptNoisily && $useStatusBar} {beep}
catch {sPrompt "$envName: how many items?" 3} numberItems
if {$numberItems == "cancel"} then {
return
} elseif {![isPositiveInteger $numberItems]} then {
beep
message "invalid input: unsigned, postive integer required"
return
if {$numberItems} then {
set body "\t\\item\[
for {set i 1} {$i < $numberItems} {incr i} {
append body "\r\r\t\\item\[
append body "\r"
} else {
set body "\t
if {[insertEnvironment $envName "" $body]} then {
nextTabStop
message "type first item label"
proc thebibliography {} {
global promptNoisily useStatusBar
set envName "thebibliography"
if {$promptNoisily && $useStatusBar} {beep}
catch {sPrompt "$envName: how many items?" 3} numberItems
if {$numberItems == "cancel"} then {
return
} elseif {![isPositiveInteger $numberItems]} then {
beep
message "invalid input: unsigned, postive integer required"
return
set arg "{9}"
if {$numberItems} then {
if {$numberItems > 9} then {set arg "{99}"}
set body "\t\\bibitem{
for {set i 1} {$i < $numberItems} {incr i} {
append body "\r\r\t\\bibitem{
append body "\r"
} else {
set body "\t
if {[insertEnvironment $envName $arg $body]} then {
set searchResult [search -s -n -f 1 -m 0 -i 1 -r 1 {(9)+} [getPos]]
eval select $searchResult
message "Change the length of the key field?"
proc slide {} { doWrapEnvironment "slide" }
proc overlay {} { doWrapEnvironment "overlay" }
proc note {} { doWrapEnvironment "note" }
# proc figure {} {
# global TeXmodeVars
# set envName "figure"
# set envArg "tbp"
# set arg "\[$envArg\]"
# set theIndentation [getIndentation [getPos]]
# append arg "\r$theIndentation\t\\centering"
# set body ""
# if { $TeXmodeVars(useBoxMacro) } then {
# set defaultMacro [car $TeXmodeVars(boxMacroNames)]
# if { $defaultMacro == "" } {
# append body "\t
# } else {
# set restOfMacros [cdr $TeXmodeVars(boxMacroNames)]
# if { ![llength $restOfMacros] } {
# append body "\t\\$defaultMacro{
# } else {
# set cmd [list prompt "Choose a boxMacro:"]
# lappend cmd $defaultMacro ""
# foreach boxMacroName $TeXmodeVars(boxMacroNames) {
# lappend cmd $boxMacroName
# }
# catch $cmd macro
# if {$macro != "cancel"} then {
# append body "\t\\$macro{
# } else {
# message "operation canceled"
# return
# }
# }
# }
# append body "\t\\caption{
# append body "\t\\label{
# if { $TeXmodeVars(useBoxMacro) } then {
# if {![insertEnvironment $envName $arg $body]} then {return}
# } else {
# wrapEnvironment $envName $arg $body
# set searchResult [search -s -n -f 1 -m 0 -i 1 -r 1 "$envArg" [getPos]]
# eval select $searchResult
# message "Modify this argument? (t=top; b=bottom; p=page; h=here; !=try harder)"
proc figure {} {
global TeXmodeVars
set envName "figure"
set envArg "tbp"
set arg "\[$envArg\]"
set theIndentation [getIndentation [getPos]]
append arg "\r$theIndentation\t\\centering"
set body ""
set macro [car $TeXmodeVars(boxMacroNames)]
if { $macro != "" } {
set restOfMacros [cdr $TeXmodeVars(boxMacroNames)]
if { ![llength $restOfMacros] } {
append body "\t\\$macro{
} else {
set cmd [list prompt "Choose a box macro:"]
lappend cmd $macro ""
foreach boxMacroName $TeXmodeVars(boxMacroNames) {
lappend cmd $boxMacroName
catch $cmd macro
if {$macro == "cancel"} then {
message "operation canceled"
return
} elseif {$macro == ""} then {
# do nothing
} else {
append body "\t\\$macro{
append body "\t\\caption{
append body "\t\\label{
if { $macro == "" } then {
wrapEnvironment $envName $arg $body
} else {
if {![insertEnvironment $envName $arg $body]} then {return}
set searchResult [search -s -n -f 1 -m 0 -i 1 -r 1 "$envArg" [getPos]]
eval select $searchResult
message "Modify this argument? (t=top; b=bottom; p=page; h=here; !=try harder)"
proc table {} {
set envName "table"
set envArg "tbp"
set arg "\[$envArg\]"
set theIndentation [getIndentation [getPos]]
append arg "\r$theIndentation\t\\centering"
# The following statement puts the caption at the top:
append arg "\r$theIndentation\t\\caption{
# The following statement puts the caption at the bottom:
# set body "\t\\caption{
append body "\t\\label{
wrapEnvironment $envName $arg $body
set searchResult [search -s -n -f 1 -m 0 -i 1 -r 1 "$envArg" [getPos]]
eval select $searchResult
message "Modify this argument? (t=top; b=bottom; p=page; h=here; !=try harder)"
proc buildRow {jmax} {
set txt "
for {set j 1} {$j < $jmax} {incr j} {
append txt " &
return $txt
proc tabular {} {
global promptNoisily useStatusBar
set envName "tabular"
if {$promptNoisily && $useStatusBar} {beep}
catch {sPrompt "$envName: how many rows?" 3} numberRows
if {$numberRows == "cancel"} then {
return
} elseif {![isPositiveInteger $numberRows]} then {
beep
message "invalid input: unsigned, postive integer required"
return
if {$promptNoisily && $useStatusBar} {beep}
catch {sPrompt "$envName: how many columns?" 3} numberCols
if {$numberCols == "cancel"} then {
return
} elseif {![isPositiveInteger $numberCols]} then {
beep
message "invalid input: unsigned, postive integer required"
return
set arg "{|"
for {set j 1} {$j <= $numberCols} {incr j} {
append arg "c|"
append arg "}"
set body "\t\\hline\r"
for {set i 1} {$i <= $numberRows} {incr i} {
append body "\t[buildRow $numberCols]"
append body " \\\\\r\t\\hline\r"
if {[insertEnvironment $envName $arg $body]} then {
set searchResult [search -s -n -f 1 -m 0 -i 1 -r 1 {(c|\|)+} [getPos]]
select [lindex $searchResult 0] [lindex $searchResult 1]
message "Modify this argument?"
proc verbatim {} { doWrapEnvironment "verbatim" }
proc quote {} { doWrapEnvironment "quote" }
proc quotation {} { doWrapEnvironment "quotation" }
proc verse {} { doWrapEnvironment "verse" }
proc flushleft {} { doWrapEnvironment "flushleft" }
proc center {} { doWrapEnvironment "center" }
proc flushright {} { doWrapEnvironment "flushright" }
proc general {} {
catch {prompt "What environment?" ""} environmentName
if {$environmentName != "cancel"} {
doWrapEnvironment "$environmentName"
#--------------------------------------------------------------------------
# Boxes:
#--------------------------------------------------------------------------
proc mbox {} {
if {[wrapObject "\\mbox{" "}
"]} then {
message "mbox set"
} else {
message "enter text"
proc makebox {} {
if {[wrapObject "\\makebox\[
\]{" "}
"]} then {
message "makebox set; enter the width and position"
} else {
message "enter the width and position of the makebox, then the text"
proc fbox {} {
if {[wrapObject "\\fbox{" "}
"]} then {
message "fbox set"
} else {
message "enter text"
proc framebox {} {
if {[wrapObject "\\framebox\[
\]{" "}
"]} then {
message "framebox set; enter the width and position"
} else {
message "enter the width and position of the framebox, then the text"
proc newsavebox {} {
if {[wrapObject "\\newsavebox{" "}
"]} then {
message "newsavebox defined"
} else {
message "enter the command name of the sbox or savebox"
proc sbox {} {
if {[wrapObject "\\sbox{
}{" "}
"]} then {
message "sbox set; enter the command name"
} else {
message "enter the command name of the sbox, then the text"
proc savebox {} {
if {[wrapObject "\\savebox{
\]{" "}
"]} then {
message "savebox set; enter the command name"
} else {
message "enter the command name of the savebox"
proc usebox {} {
if {[wrapObject "\\usebox{" "}
"]} then {
message "usebox declared"
} else {
message "enter the command name of the sbox or savebox"
proc raisebox {} {
if {[wrapObject "\\raisebox{
\]{" "}
"]} then {
message "raisebox set; enter the displacement"
} else {
message "enter the displacement of the raisebox"
proc parbox {} {
if {[wrapObject "\\parbox\[
\}{" "}
"]} then {
message "parbox set; enter the position and width"
} else {
message "enter the position \[b|c|t\] and width of the parbox, then the text"
proc minipage {} {
set arg "\[
wrapEnvironment "minipage" $arg ""
nextTabStop
message "enter the position \[b|c|t\] of the minipage, then the width"
proc rule {} {
insertObject "\\rule\[
nthTabStop -4
message "enter the displacement of the rule, then width and height"
#--------------------------------------------------------------------------
# Misc:
#--------------------------------------------------------------------------
proc verb {} {
if {[wrapObject "\\verb|" "|
"]} then {
message "verbatim text set"
} else {
message "enter verbatim text"
proc footnote {} {
if {[wrapObject "\\footnote{" "}
"]} then {
message "footnote set"
} else {
message "enter footnote"
proc marginalNote {} {
if {[wrapObject "\\marginpar{" "}
"]} then {
message "marginal note set"
} else {
message "enter marginal note"
proc label {} {
if {[wrapObject "\\label{" "}
"]} then {
message "label defined"
} else {
message "enter label"
proc ref {} {
TeXRefCompletion "ref"
proc pageref {} {
TeXRefCompletion "pageref"
proc cite {} {
if {[wrapObject "\\cite{" "}
"]} then {
message "citation made"
} else {
message "enter citation key"
proc nocite {} {
if {[wrapObject "\\nocite{" "}
"]} then {
message "citation added to the list"
} else {
message "enter citation key"
# Insert an \item or a \bibitem, depending on the context.
proc insertItem {} {
set command [eval getText [searchEnvironment]]
set environment [extractCommandArg $command]
switch $environment {
"itemize" {
set text "\\item
"enumerate" {
set text "\\item
"description" {
set text "\\item\[
"thebibliography" {
set text "\\bibitem{
default {
beep
message "insertItem: cursor in $environment environment"
return
set pos [getPos]
# Indentation should mirror that of an existing \item
# (if it exists)
insertText [openingCarriageReturn]$text
goto $pos
nextTabStop
proc quotes {} {
if {[wrapObject "`" "'
"]} then {
message "text quoted"
} else {
message "enter text"
proc dblQuotes {} {
if {[wrapObject "``" "''
"]} then {
message "text double quoted"
} else {
message "enter text"
proc ldots {} {insertObject "\\ldots"}
proc {en-dash} {} {insertObject "--"}
proc {em-dash} {} {insertObject "---"}
proc texLogo {} {insertObject "\\TeX"}
proc latexLogo {} {insertObject "\\LaTeX"}
proc latex2eLogo {} {insertObject "\\LaTeXe"}
proc today {} {insertObject "\\today"}
proc dag {} {insertObject "\\dag"}
proc ddag {} {insertObject "\\ddag"}
proc sectionMark {} {insertObject "\\S"}
proc paragraphMark {} {insertObject "\\P"}
proc copyright {} {insertObject "\\copyright"}
proc pounds {} {insertObject "\\pounds"}
#############################################################################
# Math Mode Macros
#############################################################################
#--------------------------------------------------------------------------
# Math Modes:
#--------------------------------------------------------------------------
proc texMath {} {
checkMathMode "texMath" 0
if {[wrapObject "$" "$
"]} then {
message "formula set"
} else {
message "enter formula"
proc texDisplaymath {} {
checkMathMode "texDisplaymath" 0
if {[wrapObject "$$" "$$
"]} then {
message "displayed formula set"
} else {
message "enter displayed formula"
proc latexMath {} {
checkMathMode "latexMath" 0
if {[wrapObject "\\( " " \\)
"]} then {
message "formula set"
} else {
message "enter formula"
proc latexDisplaymath {} {
checkMathMode "latexDisplaymath" 0
if {[wrapObject "\\\[ " " \\\]
"]} then {
message "displayed formula set"
} else {
message "enter displayed formula"
#--------------------------------------------------------------------------
# Math Style:
#--------------------------------------------------------------------------
proc mathit {} {
checkMathMode "mathit" 1
if {[wrapObject "\\mathit{" "}
"]} then {
message "selected text is math italic"
} else {
message "enter text to be math italic"
proc mathrm {} {
checkMathMode "mathrm" 1
if {[wrapObject "\\mathrm{" "}
"]} then {
message "selected text is math roman"
} else {
message "enter text to be math roman"
proc mathbf {} {
checkMathMode "mathbf" 1
if {[wrapObject "\\mathbf{" "}
"]} then {
message "selected text is math bold"
} else {
message "enter text to be math bold"
proc mathsf {} {
checkMathMode "mathsf" 1
if {[wrapObject "\\mathsf{" "}
"]} then {
message "selected text is math sans serif"
} else {
message "enter text to be math sans serif"
proc mathtt {} {
checkMathMode "mathtt" 1
if {[wrapObject "\\mathtt{" "}
"]} then {
message "selected text is math typewriter"
} else {
message "enter text to be math typewriter"
proc mathcal {} {
checkMathMode "mathcal" 1
# Allow upper-case arguments only:
if {[isSelection] && ![isUppercase]} then {
alertnote "argument to \\mathcal must be uppercase"
return
if {[wrapObject "\\mathcal{" "}
"]} then {
message "selected text is calligraphic"
} else {
message "enter text to be calligraphic (UPPERCASE letters only)"
proc displaystyle {} {
checkMathMode "displaystyle" 1
if {[wrapObject "{\\displaystyle " "}
"]} then {
message "displaystyle set"
} else {
message "enter displaystyle text"
proc textstyle {} {
checkMathMode "textstyle" 1
if {[wrapObject "{\\textstyle " "}
"]} then {
message "textstyle set"
} else {
message "enter textstyle text"
proc scriptstyle {} {
checkMathMode "scriptstyle" 1
if {[wrapObject "{\\scriptstyle " "}
"]} then {
message "scriptstyle set"
} else {
message "enter scriptstyle text"
proc scriptscriptstyle {} {
checkMathMode "scriptscriptstyle" 1
if {[wrapObject "{\\scriptscriptstyle " "}
"]} then {
message "scriptscriptstyle set"
} else {
message "enter scriptscriptstyle text"
#--------------------------------------------------------------------------
# Math Environments:
#--------------------------------------------------------------------------
proc math {} { checkMathMode "math" 0; doWrapEnvironment "math" }
proc displaymath {} {
checkMathMode "displaymath" 0
global TeXmodeVars
if { $TeXmodeVars(useBrackets) } {
doWrapStructure {\[} {} {\]}
} else {
doWrapEnvironment "displaymath"
proc equation {} {
checkMathMode "equation" 0
set envName "equation"
set body "\t\\label{
if {[wrapEnvironment $envName "" $body]} then {
set msgText "equation wrapped"
} else {
set msgText "enter equation"
nextTabStop
message $msgText
proc eqnarrayStar {} {
global promptNoisily useStatusBar
checkMathMode "eqnarrayStar" 0
set envName "eqnarray*"
if {$promptNoisily && $useStatusBar} {beep}
catch {sPrompt "$envName: how many rows?" 3} numberRows
if {$numberRows == "cancel"} then {
return
} elseif {![isPositiveInteger $numberRows]} then {
beep
message "invalid input: unsigned, postive integer required"
return
set row "\t[buildRow 3]"
for {set i 1} {$i < $numberRows} {incr i} {
append body $row
append body " \\\\\r"
append body $row
append body "\r"
if {[insertEnvironment $envName "" $body]} then {
nextTabStop
message "type first item"
proc eqnarray {} {
global promptNoisily useStatusBar
checkMathMode "eqnarray" 0
set envName "eqnarray"
if {$promptNoisily && $useStatusBar} {beep}
catch {sPrompt "$envName: how many rows?" 3} numberRows
if {$numberRows == "cancel"} then {
return
} elseif {![isPositiveInteger $numberRows]} then {
beep
message "invalid input: unsigned, postive integer required"
return
set row "\t[buildRow 3]\r\t\\label{
for {set i 1} {$i < $numberRows} {incr i} {
append body $row
append body " \\\\\r"
append body $row
append body "\r"
if {[insertEnvironment $envName "" $body]} then {
nextTabStop
message "type first item"
proc myArray {} {
global promptNoisily useStatusBar
checkMathMode "myArray" 1
set envName "array"
if {$promptNoisily && $useStatusBar} {beep}
catch {sPrompt "$envName: how many rows?" 3} numberRows
if {$numberRows == "cancel"} then {
return
} elseif {![isPositiveInteger $numberRows]} then {
beep
message "invalid input: unsigned, postive integer required"
return
if {$promptNoisily && $useStatusBar} {beep}
catch {sPrompt "$envName: how many columns?" 3} numberCols
if {$numberCols == "cancel"} then {
return
} elseif {![isPositiveInteger $numberCols]} then {
beep
message "invalid input: unsigned, postive integer required"
return
set arg "{"
for {set j 1} {$j <= $numberCols} {incr j} {
append arg "c"
append arg "}"
set row "\t[buildRow $numberCols]"
for {set i 1} {$i < $numberRows} {incr i} {
append body $row
append body " \\\\\r"
append body $row
append body "\r"
if {[insertEnvironment $envName $arg $body]} then {
set searchResult [search -s -n -f 1 -m 0 -i 1 -r 1 {c+} [getPos]]
select [lindex $searchResult 0] [lindex $searchResult 1]
message "Modify this argument?"
#--------------------------------------------------------------------------
# Formulas:
#--------------------------------------------------------------------------
proc subscript {} {
checkMathMode "subscript" 1
if {[wrapObject "_{" "}
"]} then {
message "subscript set"
} else {
message "enter subscript"
proc superscript {} {
checkMathMode "superscript" 1
if {[wrapObject "^{" "}
"]} then {
message "superscript set"
} else {
message "enter superscript"
proc fraction {} {
checkMathMode "fraction" 1
set currentPos [getPos]
if {[isSelection]} then {
set selection [getSelect]
set args [split $selection /]
set len [llength $args]
deleteText $currentPos [selEnd]
if {$len == 1} then {
insertObject "\\frac{$selection}{
goto $currentPos
nextTabStop
message "enter denominator"
} else {
set firstArg [lindex $args 0]
set restArgs [lrange $args 1 [expr $len-1]]
insertObject "\\frac{$firstArg}{[join $restArgs /]}"
if {$len > 2} {message "beware of multiple /"}
} else {
insertObject "\\frac{
goto $currentPos
nextTabStop
message "enter numerator"
proc squareRoot {} {
checkMathMode "squareRoot" 1
if {[wrapObject "\\sqrt{" "}
"]} then {
message "square root set"
} else {
message "enter formula"
proc nthRoot {} {
checkMathMode "nthRoot" 1
if {[wrapObject "\\sqrt\[
\]{" "}
"]} then {
message "enter root"
} else {
message "enter root, then formula"
proc oneParameter {} {
checkMathMode "oneParameter" 1
if {[wrapObject "\\
{" "}
"]} then {
message "enter command name"
} else {
message "enter command name, press <Tab>, enter argument"
proc twoParameters {} {
checkMathMode "twoParameters" 1
if {[wrapObject "\\
{" "}{
"]} then {
message "enter command name"
} else {
message "enter command name, press <Tab>, enter argument, etc."
#--------------------------------------------------------------------------
# Greek:
#--------------------------------------------------------------------------
proc alpha {} {checkMathMode "alpha" 1; insertObject "\\alpha"}
proc beta {} {checkMathMode "beta" 1; insertObject "\\beta"}
proc gamma {} {checkMathMode "gamma" 1; insertObject "\\gamma"}
proc delta {} {checkMathMode "delta" 1; insertObject "\\delta"}
proc epsilon {} {checkMathMode "epsilon" 1; insertObject "\\epsilon"}
proc zeta {} {checkMathMode "zeta" 1; insertObject "\\zeta"}
proc eta {} {checkMathMode "eta" 1; insertObject "\\eta"}
proc theta {} {checkMathMode "theta" 1; insertObject "\\theta"}
proc iota {} {checkMathMode "iota" 1; insertObject "\\iota"}
proc kappa {} {checkMathMode "kappa" 1; insertObject "\\kappa"}
proc lambda {} {checkMathMode "lambda" 1; insertObject "\\lambda"}
proc mu {} {checkMathMode "mu" 1; insertObject "\\mu"}
proc nu {} {checkMathMode "nu" 1; insertObject "\\nu"}
proc xi {} {checkMathMode "xi" 1; insertObject "\\xi"}
proc omicron {} {checkMathMode "omicron" 1; insertObject "o"}
proc pi {} {checkMathMode "pi" 1; insertObject "\\pi"}
proc rho {} {checkMathMode "rho" 1; insertObject "\\rho"}
proc sigma {} {checkMathMode "sigma" 1; insertObject "\\sigma"}
proc tau {} {checkMathMode "tau" 1; insertObject "\\tau"}
proc upsilon {} {checkMathMode "upsilon" 1; insertObject "\\upsilon"}
proc phi {} {checkMathMode "phi" 1; insertObject "\\phi"}
proc chi {} {checkMathMode "chi" 1; insertObject "\\chi"}
proc psi {} {checkMathMode "psi" 1; insertObject "\\psi"}
proc omega {} {checkMathMode "omega" 1; insertObject "\\omega"}
proc Gamma {} {checkMathMode "Gamma" 1; insertObject "\\Gamma"}
proc Delta {} {checkMathMode "Delta" 1; insertObject "\\Delta"}
proc Theta {} {checkMathMode "Theta" 1; insertObject "\\Theta"}
proc Lambda {} {checkMathMode "Lambda" 1; insertObject "\\Lambda"}
proc Xi {} {checkMathMode "Xi" 1; insertObject "\\Xi"}
proc Pi {} {checkMathMode "Pi" 1; insertObject "\\Pi"}
proc Sigma {} {checkMathMode "Sigma" 1; insertObject "\\Sigma"}
proc Upsilon {} {checkMathMode "Upsilon" 1; insertObject "\\Upsilon"}
proc Phi {} {checkMathMode "Phi" 1; insertObject "\\Phi"}
proc Psi {} {checkMathMode "Psi" 1; insertObject "\\Psi"}
proc Omega {} {checkMathMode "Omega" 1; insertObject "\\Omega"}
proc varepsilon {} {checkMathMode "varepsilon" 1; insertObject "\\varepsilon"}
proc vartheta {} {checkMathMode "vartheta" 1; insertObject "\\vartheta"}
proc varpi {} {checkMathMode "varpi" 1; insertObject "\\varpi"}
proc varrho {} {checkMathMode "varrho" 1; insertObject "\\varrho"}
proc varsigma {} {checkMathMode "varsigma" 1; insertObject "\\varsigma"}
proc varphi {} {checkMathMode "varphi" 1; insertObject "\\varphi"}
#--------------------------------------------------------------------------
# Binary Ops:
#--------------------------------------------------------------------------
proc pm {} {checkMathMode "pm" 1; insertObject "\\pm"}
proc mp {} {checkMathMode "mp" 1; insertObject "\\mp"}
proc times {} {checkMathMode "times" 1; insertObject "\\times"}
proc div {} {checkMathMode "div" 1; insertObject "\\div"}
proc ast {} {checkMathMode "ast" 1; insertObject "\\ast"}
proc star {} {checkMathMode "star" 1; insertObject "\\star"}
proc circ {} {checkMathMode "circ" 1; insertObject "\\circ"}
proc bullet {} {checkMathMode "bullet" 1; insertObject "\\bullet"}
proc cdot {} {checkMathMode "cdot" 1; insertObject "\\cdot"}
proc cap {} {checkMathMode "cap" 1; insertObject "\\cap"}
proc cup {} {checkMathMode "cup" 1; insertObject "\\cup"}
proc uplus {} {checkMathMode "uplus" 1; insertObject "\\uplus"}
proc sqcap {} {checkMathMode "sqcap" 1; insertObject "\\sqcap"}
proc sqcup {} {checkMathMode "sqcup" 1; insertObject "\\sqcup"}
proc vee {} {checkMathMode "vee" 1; insertObject "\\vee"}
proc wedge {} {checkMathMode "wedge" 1; insertObject "\\wedge"}
proc setminus {} {checkMathMode "setminus" 1; insertObject "\\setminus"}
proc wr {} {checkMathMode "wr" 1; insertObject "\\wr"}
proc diamond {} {checkMathMode "diamond" 1; insertObject "\\diamond"}
proc bigtriangleup {} {
checkMathMode "bigtriangleup" 1; insertObject "\\bigtriangleup"
proc bigtriangledown {} {
checkMathMode "bigtriangledown" 1; insertObject "\\bigtriangledown"
proc triangleleft {} {
checkMathMode "triangleleft" 1; insertObject "\\triangleleft"
proc triangleright {} {
checkMathMode "triangleright" 1; insertObject "\\triangleright"
proc lhd {} {
if {[isSymbolPackageLoaded]} then {
checkMathMode "lhd" 1; insertObject "\\lhd"
proc rhd {} {
if {[isSymbolPackageLoaded]} then {
checkMathMode "rhd" 1; insertObject "\\rhd"
proc unlhd {} {
if {[isSymbolPackageLoaded]} then {
checkMathMode "unlhd" 1; insertObject "\\unlhd"
proc unrhd {} {
if {[isSymbolPackageLoaded]} then {
checkMathMode "unrhd" 1; insertObject "\\unrhd"
proc oplus {} {checkMathMode "oplus" 1; insertObject "\\oplus"}
proc ominus {} {checkMathMode "ominus" 1; insertObject "\\ominus"}
proc otimes {} {checkMathMode "otimes" 1; insertObject "\\otimes"}
proc oslash {} {checkMathMode "oslash" 1; insertObject "\\oslash"}
proc odot {} {checkMathMode "odot" 1; insertObject "\\odot"}
proc bigcirc {} {checkMathMode "bigcirc" 1; insertObject "\\bigcirc"}
proc dagger {} {checkMathMode "dagger" 1; insertObject "\\dagger"}
proc ddagger {} {checkMathMode "ddagger" 1; insertObject "\\ddagger"}
proc amalg {} {checkMathMode "amalg" 1; insertObject "\\amalg"}
#--------------------------------------------------------------------------
# Relations:
#--------------------------------------------------------------------------
proc leq {} {checkMathMode "leq" 1; insertObject "\\leq"}
proc prec {} {checkMathMode "prec" 1; insertObject "\\prec"}
proc preceq {} {checkMathMode "preceq" 1; insertObject "\\preceq"}
proc myLl {} {checkMathMode "myLl" 1; insertObject "\\ll"}
proc subset {} {checkMathMode "subset" 1; insertObject "\\subset"}
proc subseteq {} {checkMathMode "subseteq" 1; insertObject "\\subseteq"}
proc sqsubset {} {
if {[isSymbolPackageLoaded]} then {
checkMathMode "sqsubset" 1; insertObject "\\sqsubset"
proc sqsubseteq {} {checkMathMode "sqsubseteq" 1; insertObject "\\sqsubseteq"}
proc in {} {checkMathMode "in" 1; insertObject "\\in"}
proc vdash {} {checkMathMode "vdash" 1; insertObject "\\vdash"}
proc geq {} {checkMathMode "geq" 1; insertObject "\\geq"}
proc succ {} {checkMathMode "succ" 1; insertObject "\\succ"}
proc succeq {} {checkMathMode "succeq" 1; insertObject "\\succeq"}
proc gg {} {checkMathMode "gg" 1; insertObject "\\gg"}
proc supset {} {checkMathMode "supset" 1; insertObject "\\supset"}
proc supseteq {} {checkMathMode "supseteq" 1; insertObject "\\supseteq"}
proc sqsupset {} {
if {[isSymbolPackageLoaded]} then {
checkMathMode "sqsupset" 1; insertObject "\\sqsupset"
proc sqsupseteq {} {checkMathMode "sqsupseteq" 1; insertObject "\\sqsupseteq"}
proc ni {} {checkMathMode "ni" 1; insertObject "\\ni"}
proc dashv {} {checkMathMode "dashv" 1; insertObject "\\dashv"}
proc equiv {} {checkMathMode "equiv" 1; insertObject "\\equiv"}
proc sim {} {checkMathMode "sim" 1; insertObject "\\sim"}
proc simeq {} {checkMathMode "simeq" 1; insertObject "\\simeq"}
proc asymp {} {checkMathMode "asymp" 1; insertObject "\\asymp"}
proc approx {} {checkMathMode "approx" 1; insertObject "\\approx"}
proc cong {} {checkMathMode "cong" 1; insertObject "\\cong"}
proc neq {} {checkMathMode "neq" 1; insertObject "\\neq"}
proc doteq {} {checkMathMode "doteq" 1; insertObject "\\doteq"}
proc propto {} {checkMathMode "propto" 1; insertObject "\\propto"}
proc models {} {checkMathMode "models" 1; insertObject "\\models"}
proc perp {} {checkMathMode "perp" 1; insertObject "\\perp"}
proc mid {} {checkMathMode "mid" 1; insertObject "\\mid"}
proc parallel {} {checkMathMode "parallel" 1; insertObject "\\parallel"}
proc bowtie {} {checkMathMode "bowtie" 1; insertObject "\\bowtie"}
proc myJoin {} {
if {[isSymbolPackageLoaded]} then {
checkMathMode "myJoin" 1; insertObject "\\join"
proc smile {} {checkMathMode "smile" 1; insertObject "\\smile"}
proc frown {} {checkMathMode "frown" 1; insertObject "\\frown"}
#--------------------------------------------------------------------------
# Arrows:
#--------------------------------------------------------------------------
proc leftarrow {} {checkMathMode "leftarrow" 1; insertObject "\\leftarrow"}
proc Leftarrow {} {checkMathMode "Leftarrow" 1; insertObject "\\Leftarrow"}
proc rightarrow {} {checkMathMode "rightarrow" 1; insertObject "\\rightarrow"}
proc Rightarrow {} {checkMathMode "Rightarrow" 1; insertObject "\\Rightarrow"}
proc leftrightarrow {} {
checkMathMode "leftrightarrow" 1; insertObject "\\leftrightarrow"
proc Leftrightarrow {} {
checkMathMode "Leftrightarrow" 1; insertObject "\\Leftrightarrow"
proc mapsto {} {checkMathMode "mapsto" 1; insertObject "\\mapsto"}
proc hookleftarrow {} {
checkMathMode "hookleftarrow" 1; insertObject "\\hookleftarrow"
proc leftharpoonup {} {
checkMathMode "leftharpoonup" 1; insertObject "\\leftharpoonup"
proc leftharpoondown {} {
checkMathMode "leftharpoondown" 1; insertObject "\\leftharpoondown"
proc rightleftharpoons {} {
checkMathMode "rightleftharpoons" 1; insertObject "\\rightleftharpoons"
proc longleftarrow {} {
checkMathMode "longleftarrow" 1; insertObject "\\longleftarrow"
proc Longleftarrow {} {
checkMathMode "Longleftarrow" 1; insertObject "\\Longleftarrow"
proc longrightarrow {} {
checkMathMode "longrightarrow" 1; insertObject "\\longrightarrow"
proc Longrightarrow {} {
checkMathMode "Longrightarrow" 1; insertObject "\\Longrightarrow"
proc longleftrightarrow {} {
checkMathMode "longleftrightarrow" 1; insertObject "\\longleftrightarrow"
proc Longleftrightarrow {} {
checkMathMode "Longleftrightarrow" 1; insertObject "\\Longleftrightarrow"
proc longmapsto {} {checkMathMode "longmapsto" 1; insertObject "\\longmapsto"}
proc hookrightarrow {} {
checkMathMode "hookrightarrow" 1; insertObject "\\hookrightarrow"
proc rightharpoonup {} {
checkMathMode "rightharpoonup" 1; insertObject "\\rightharpoonup"
proc rightharpoondown {} {
checkMathMode "rightharpoondown" 1; insertObject "\\rightharpoondown"
proc leadsto {} {
if {[isSymbolPackageLoaded]} then {
checkMathMode "leadsto" 1; insertObject "\\leadsto"
proc uparrow {} {checkMathMode "uparrow" 1; insertObject "\\uparrow"}
proc Uparrow {} {checkMathMode "Uparrow" 1; insertObject "\\Uparrow"}
proc downarrow {} {checkMathMode "downarrow" 1; insertObject "\\downarrow"}
proc Downarrow {} {checkMathMode "Downarrow" 1; insertObject "\\Downarrow"}
proc updownarrow {} {checkMathMode "updownarrow" 1; insertObject "\\updownarrow"}
proc Updownarrow {} {checkMathMode "Updownarrow" 1; insertObject "\\Updownarrow"}
proc nearrow {} {checkMathMode "nearrow" 1; insertObject "\\nearrow"}
proc searrow {} {checkMathMode "searrow" 1; insertObject "\\searrow"}
proc swarrow {} {checkMathMode "swarrow" 1; insertObject "\\swarrow"}
proc nwarrow {} {checkMathMode "nwarrow" 1; insertObject "\\nwarrow"}
#--------------------------------------------------------------------------
# Dots:
#--------------------------------------------------------------------------
proc cdots {} {checkMathMode "cdots" 1; insertObject "\\cdots"}
proc vdots {} {checkMathMode "vdots" 1; insertObject "\\vdots"}
proc ddots {} {checkMathMode "ddots" 1; insertObject "\\ddots"}
#--------------------------------------------------------------------------
# Symbols:
#--------------------------------------------------------------------------
proc aleph {} {checkMathMode "aleph" 1; insertObject "\\aleph"}
proc hbar {} {checkMathMode "hbar" 1; insertObject "\\hbar"}
proc imath {} {checkMathMode "imath" 1; insertObject "\\imath"}
proc jmath {} {checkMathMode "jmath" 1; insertObject "\\jmath"}
proc ell {} {checkMathMode "ell" 1; insertObject "\\ell"}
proc wp {} {checkMathMode "wp" 1; insertObject "\\wp"}
proc Re {} {checkMathMode "Re" 1; insertObject "\\Re"}
proc Im {} {checkMathMode "Im" 1; insertObject "\\Im"}
proc mho {} {
if {[isSymbolPackageLoaded]} then {
checkMathMode "mho" 1; insertObject "\\mho"
proc prime {} {checkMathMode "prime" 1; insertObject "\\prime"}
proc emptyset {} {checkMathMode "emptyset" 1; insertObject "\\emptyset"}
proc nabla {} {checkMathMode "nabla" 1; insertObject "\\nabla"}
proc surd {} {checkMathMode "surd" 1; insertObject "\\surd"}
proc top {} {checkMathMode "top" 1; insertObject "\\top"}
proc bot {} {checkMathMode "bot" 1; insertObject "\\bot"}
# proc | {} {checkMathMode "|" 1; insertObject "\\|"}
proc angle {} {checkMathMode "angle" 1; insertObject "\\angle"}
proc forall {} {checkMathMode "forall" 1; insertObject "\\forall"}
proc exists {} {checkMathMode "exists" 1; insertObject "\\exists"}
proc neg {} {checkMathMode "neg" 1; insertObject "\\neg"}
proc flat {} {checkMathMode "flat" 1; insertObject "\\flat"}
proc natural {} {checkMathMode "natural" 1; insertObject "\\natural"}
proc sharp {} {checkMathMode "sharp" 1; insertObject "\\sharp"}
proc backslash {} {checkMathMode "backslash" 1; insertObject "\\backslash"}
proc partial {} {checkMathMode "partial" 1; insertObject "\\partial"}
proc infty {} {checkMathMode "infty" 1; insertObject "\\infty"}
proc Box {} {
if {[isSymbolPackageLoaded]} then {
checkMathMode "Box" 1; insertObject "\\Box"
proc Diamond {} {
if {[isSymbolPackageLoaded]} then {
checkMathMode "Diamond" 1; insertObject "\\Diamond"
proc triangle {} {checkMathMode "triangle" 1; insertObject "\\triangle"}
proc clubsuit {} {checkMathMode "clubsuit" 1; insertObject "\\clubsuit"}
proc diamondsuit {} {checkMathMode "diamondsuit" 1; insertObject "\\diamondsuit"}
proc heartsuit {} {checkMathMode "heartsuit" 1; insertObject "\\heartsuit"}
proc spadesuit {} {checkMathMode "spadesuit" 1; insertObject "\\spadesuit"}
#--------------------------------------------------------------------------
# Functions:
#--------------------------------------------------------------------------
proc arccos {} {checkMathMode "arccos" 1; insertObject "\\arccos"}
proc arcsin {} {checkMathMode "arcsin" 1; insertObject "\\arcsin"}
proc arctan {} {checkMathMode "arctan" 1; insertObject "\\arctan"}
proc arg {} {checkMathMode "arg" 1; insertObject "\\arg"}
proc cos {} {checkMathMode "cos" 1; insertObject "\\cos"}
proc cosh {} {checkMathMode "cosh" 1; insertObject "\\cosh"}
proc cot {} {checkMathMode "cot" 1; insertObject "\\cot"}
proc coth {} {checkMathMode "coth" 1; insertObject "\\coth"}
proc csc {} {checkMathMode "csc" 1; insertObject "\\csc"}
proc deg {} {checkMathMode "deg" 1; insertObject "\\deg"}
proc det {} {checkMathMode "det" 1; insertObject "\\det"}
proc dim {} {checkMathMode "dim" 1; insertObject "\\dim"}
proc exp {} {checkMathMode "exp" 1; insertObject "\\exp"}
proc gcd {} {checkMathMode "gcd" 1; insertObject "\\gcd"}
proc hom {} {checkMathMode "hom" 1; insertObject "\\hom"}
# proc inf {} {checkMathMode "inf" 1; insertObject "\\inf"}
proc inf {} {
checkMathMode "inf" 1
if {[wrapObject "\\inf_{" "}
"]} then {
message "limit set"
} else {
message "enter limit"
proc ker {} {checkMathMode "ker" 1; insertObject "\\ker"}
proc lg {} {checkMathMode "lg" 1; insertObject "\\lg"}
# proc lim {} {checkMathMode "lim" 1; insertObject "\\lim"}
proc lim {} {
checkMathMode "lim" 1
if {[wrapObject "\\lim_{" "}
"]} then {
message "limit set"
} else {
message "enter limit"
# proc liminf {} {checkMathMode "liminf" 1; insertObject "\\liminf"}
proc liminf {} {
checkMathMode "liminf" 1
if {[wrapObject "\\liminf_{" "}
"]} then {
message "limit set"
} else {
message "enter limit"
# proc limsup {} {checkMathMode "limsup" 1; insertObject "\\limsup"}
proc limsup {} {
checkMathMode "limsup" 1
if {[wrapObject "\\limsup_{" "}
"]} then {
message "limit set"
} else {
message "enter limit"
proc ln {} {checkMathMode "ln" 1; insertObject "\\ln"}
proc log {} {checkMathMode "log" 1; insertObject "\\log"}
# proc max {} {checkMathMode "max" 1; insertObject "\\max"}
proc max {} {
checkMathMode "max" 1
if {[wrapObject "\\max_{" "}
"]} then {
message "limit set"
} else {
message "enter limit"
# proc min {} {checkMathMode "min" 1; insertObject "\\min"}
proc min {} {
checkMathMode "min" 1
if {[wrapObject "\\min_{" "}
"]} then {
message "limit set"
} else {
message "enter limit"
proc Pr {} {checkMathMode "Pr" 1; insertObject "\\Pr"}
proc sec {} {checkMathMode "sec" 1; insertObject "\\sec"}
proc sin {} {checkMathMode "sin" 1; insertObject "\\sin"}
proc sinh {} {checkMathMode "sinh" 1; insertObject "\\sinh"}
# proc sup {} {checkMathMode "sup" 1; insertObject "\\sup"}
proc sup {} {
checkMathMode "sup" 1
if {[wrapObject "\\sup_{" "}
"]} then {
message "limit set"
} else {
message "enter limit"
proc tan {} {checkMathMode "tan" 1; insertObject "\\tan"}
proc tanh {} {checkMathMode "tanh" 1; insertObject "\\tanh"}
proc bmod {} {checkMathMode "bmod" 1; insertObject "\\bmod"}
proc pmod {} {
checkMathMode "pmod" 1
if {[wrapObject "\\pmod{" "}
"]} then {
message "parenthesized mod set"
} else {
message "enter formula"
#--------------------------------------------------------------------------
# Large Ops:
#--------------------------------------------------------------------------
proc insertLargeOp {commandName} {
checkMathMode "$commandName" 1
set currentPos [getPos]
insertObject "\\$commandName\_{
goto $currentPos
nextTabStop
proc sum {} {insertLargeOp "sum"}
proc prod {} {insertLargeOp "prod"}
proc coprod {} {insertLargeOp "coprod"}
proc int {} {insertLargeOp "int"}
proc oint {} {insertLargeOp "oint"}
proc bigcap {} {insertLargeOp "bigcap"}
proc bigcup {} {insertLargeOp "bigcup"}
proc bigsqcup {} {insertLargeOp "bigsqcup"}
proc bigvee {} {insertLargeOp "bigvee"}
proc bigwedge {} {insertLargeOp "bigwedge"}
proc bigodot {} {insertLargeOp "bigodot"}
proc bigotimes {} {insertLargeOp "bigotimes"}
proc bigoplus {} {insertLargeOp "bigoplus"}
proc biguplus {} {insertLargeOp "biguplus"}
#--------------------------------------------------------------------------
# Delimiters:
#--------------------------------------------------------------------------
proc delimitObject {leftDelim rightDelim} {
if {[wrapObject $leftDelim $rightDelim]} then {
message "formula delimited"
} else {
message "enter formula"
proc parentheses {} { checkMathMode "parentheses" 1; delimitObject "(" ")
proc brackets {} { checkMathMode "brackets" 1; delimitObject "\[" "\]
proc braces {} { checkMathMode "braces" 1; delimitObject "\\\{" "\\\}
proc absoluteValue {} { checkMathMode "absoluteValue" 1; delimitObject "|" "|
proc getDelims {} {
catch {prompt "Choose delimiters:" "parentheses" "" "parentheses" \
"brackets" "braces" "angle brackets" "vertical bars" \
"double bars" "ceiling" "floor"} delimType
if {$delimType != "cancel"} then {
switch $delimType {
"parentheses" {
set leftDelim "("
set rightDelim ")"
"brackets" {
set leftDelim "\["
set rightDelim "\]"
"braces" {
set leftDelim "\\\{"
set rightDelim "\\\}"
"vertical bars" {
set leftDelim "|"
set rightDelim "|"
"double bars" {
set leftDelim "\\|"
set rightDelim "\\|"
"angle brackets" {
set leftDelim "\\langle"
set rightDelim "\\rangle"
"ceiling" {
set leftDelim "\\lceil"
set rightDelim "\\rceil"
"floor" {
set leftDelim "\\lfloor"
set rightDelim "\\rfloor"
default {
alertnote "\"$delimType\" not recognized"
return ""
return [list $leftDelim $rightDelim]
} else {return ""}
proc otherDelims {} {
checkMathMode "otherDelims" 1
set delims [getDelims]
if {$delims != ""} then {
set leftDelim [lindex $delims 0]
set rightDelim [lindex $delims 1]
delimitObject "$leftDelim" "$rightDelim
proc {half-openInterval} {} {
checkMathMode "half-openInterval" 1; delimitObject "(" "\]
proc {half-closedInterval} {} {
checkMathMode "half-closedInterval" 1; delimitObject "\[" ")
proc insertBigDelims {leftDelim rightDelim isMultiline} {
checkMathMode "insertBigDelims" 1
if {$isMultiline} then {
doWrapStructure $leftDelim "" $rightDelim
} else {
if { [wrapObject $leftDelim $rightDelim] } then {
message "formula delimited"
} else {
message "enter formula"
proc bigParens {} {
checkMathMode "bigParens" 1; insertBigDelims "\\left(" "\\right)
proc multiBigParens {} {
checkMathMode "multiBigParens" 1; insertBigDelims "\\left(" "\\right)
proc bigBrackets {} {
checkMathMode "bigBrackets" 1; insertBigDelims "\\left\[" "\\right\]
proc multiBigBrackets {} {
checkMathMode "multiBigBrackets" 1; insertBigDelims "\\left\[" "\\right\]
proc bigBraces {} {
checkMathMode "bigBraces" 1; insertBigDelims "\\left\\\{" "\\right\\\}
proc multiBigBraces {} {
checkMathMode "multiBigBraces" 1; insertBigDelims "\\left\\\{" "\\right\\\}
proc bigAbsValue {} {
checkMathMode "bigAbsValue" 1; insertBigDelims "\\left|" "\\right|
proc multiBigAbsValue {} {
checkMathMode "multiBigAbsValue" 1; insertBigDelims "\\left|" "\\right|
proc doOtherBigDelims {name isMultiline} {
checkMathMode $name 1
set delims [getDelims]
if {$delims != ""} then {
append leftDelim "\\left" [lindex $delims 0]
append rightDelim "\\right" [lindex $delims 1]
insertBigDelims "$leftDelim" "$rightDelim
" $isMultiline
proc otherBigDelims {} {
doOtherBigDelims "otherBigDelims" 0
proc otherMultiBigDelims {} {
doOtherBigDelims "otherMultiBigDelims" 1
proc bigLeftBrace {} {
checkMathMode "bigLeftBrace" 1
insertBigDelims "\\left\\\{" "\\right.
proc multiBigLeftBrace {} {
checkMathMode "multiBigLeftBrace" 1
insertBigDelims "\\left\\\{" "\\right.
proc doOtherMixedBigDelims {name isMultiline} {
checkMathMode $name 1
catch {prompt "Choose LEFT delimiter:" "parenthesis" "" "parenthesis" \
"bracket" "brace" "vertical bar" "double bar" \
"angle bracket" "ceiling" "floor" "slash" "backslash" \
"none"} delimType
if {$delimType != "cancel"} then {
switch $delimType {
"parenthesis" {set leftDelim "("}
"bracket" {set leftDelim "\["}
"brace" {set leftDelim "\\\{"}
"vertical bar" {set leftDelim "|"}
"double bar" {set leftDelim "\\|"}
"angle bracket" {set leftDelim "\\langle"}
"ceiling" {set leftDelim "\\lceil"}
"floor" {set leftDelim "\\lfloor"}
"slash" {set leftDelim "/"}
"backslash" {set leftDelim "\\backslash"}
"none" {set leftDelim "."}
default {
alertnote "\"$delimType\" not recognized"
return
catch {prompt "Choose RIGHT delimiter:" "parenthesis" "" "parenthesis" \
"bracket" "brace" "vertical bar" "double bar" \
"angle bracket" "ceiling" "floor" "slash" "backslash" \
"none"} delimType
if {$delimType != "cancel"} then {
switch $delimType {
"parenthesis" {set rightDelim ")"}
"bracket" {set rightDelim "\]"}
"brace" {set rightDelim "\\\}"}
"vertical bar" {set rightDelim "|"}
"double bar" {set rightDelim "\\|"}
"angle bracket" {set rightDelim "\\rangle"}
"ceiling" {set rightDelim "\\rceil"}
"floor" {set rightDelim "\\rfloor"}
"slash" {set rightDelim "/"}
"backslash" {set rightDelim "\\backslash"}
"none" {set rightDelim "."}
default {
alertnote "\"$delimType\" not recognized"
return
}
insertBigDelims "\\left$leftDelim" "\\right$rightDelim
" $isMultiline
proc otherMixedBigDelims {} {
doOtherMixedBigDelims "otherMixedBigDelims" 0
proc otherMultiMixedBigDelims {} {
doOtherMixedBigDelims "otherMultiMixedBigDelims" 1
#--------------------------------------------------------------------------
# Accents:
#--------------------------------------------------------------------------
proc acute {} {
checkMathMode "acute" 1
if {[isSelection] > 1} then {
alertnote "Warning: only a single character may be accented!"
if {[wrapObject "\\acute{" "}
"]} then {
message "accent set"
} else {
message "enter one character"
proc bar {} {
checkMathMode "bar" 1
if {[isSelection] > 1} then {
alertnote "Warning: only a single character may be accented!"
if {[wrapObject "\\bar{" "}
"]} then {
message "accent set"
} else {
message "enter one character"
proc breve {} {
checkMathMode "breve" 1
if {[isSelection] > 1} then {
alertnote "Warning: only a single character may be accented!"
if {[wrapObject "\\breve{" "}
"]} then {
message "accent set"
} else {
message "enter one character"
proc check {} {
checkMathMode "check" 1
if {[isSelection] > 1} then {
alertnote "Warning: only a single character may be accented!"
if {[wrapObject "\\check{" "}
"]} then {
message "accent set"
} else {
message "enter one character"
proc dot {} {
checkMathMode "dot" 1
if {[isSelection] > 1} then {
alertnote "Warning: only a single character may be accented!"
if {[wrapObject "\\dot{" "}
"]} then {
message "accent set"
} else {
message "enter one character"
proc ddot {} {
checkMathMode "ddot" 1
if {[isSelection] > 1} then {
alertnote "Warning: only a single character may be accented!"
if {[wrapObject "\\ddot{" "}
"]} then {
message "accent set"
} else {
message "enter one character"
proc grave {} {
checkMathMode "grave" 1
if {[isSelection] > 1} then {
alertnote "Warning: only a single character may be accented!"
if {[wrapObject "\\grave{" "}
"]} then {
message "accent set"
} else {
message "enter one character"
proc hat {} {
checkMathMode "hat" 1
if {[isSelection] > 1} then {
alertnote "Warning: only a single character may be accented!"
if {[wrapObject "\\hat{" "}
"]} then {
message "accent set"
} else {
message "enter one character"
proc tilde {} {
checkMathMode "tilde" 1
if {[isSelection] > 1} then {
alertnote "Warning: only a single character may be accented!"
if {[wrapObject "\\tilde{" "}
"]} then {
message "accent set"
} else {
message "enter one character"
proc vec {} {
checkMathMode "vec" 1
if {[isSelection] > 1} then {
alertnote "Warning: only a single character may be accented!"
if {[wrapObject "\\vec{" "}
"]} then {
message "accent set"
} else {
message "enter one character"
proc widehat {} {
checkMathMode "widehat" 1
if {[isSelection] > 3} then {
alertnote "Warning: only a few characters may be accented!"
if {[wrapObject "\\widehat{" "}
"]} then {
message "accent set"
} else {
message "enter a few characters"
proc widetilde {} {
checkMathMode "widetilde" 1
if {[isSelection] > 3} then {
alertnote "Warning: only a few characters may be accented!"
if {[wrapObject "\\widetilde{" "}
"]} then {
message "accent set"
} else {
message "enter a few characters"
proc imath {} {checkMathMode "imath" 1; insertObject "\\imath"}
proc jmath {} {checkMathMode "jmath" 1; insertObject "\\jmath"}
#--------------------------------------------------------------------------
# Grouping:
#--------------------------------------------------------------------------
proc underline {} {
checkMathMode "underline" 1
if {[wrapObject "\\underline{" "}
"]} then {
message "selection underlined"
} else {
message "enter text"
proc overline {} {
checkMathMode "overline" 1
if {[wrapObject "\\overline{" "}
"]} then {
message "selection overlined"
} else {
message "enter text"
proc underbrace {} {
checkMathMode "underbrace" 1
if {[wrapObject "\\underbrace{" "}
"]} then {
message "selection underbraced"
} else {
message "enter text"
proc overbrace {} {
checkMathMode "overbrace" 1
if {[wrapObject "\\overbrace{" "}
"]} then {
message "selection overbraced"
} else {
message "enter text"
proc overrightarrow {} {
checkMathMode "overrightarrow" 1
if {[wrapObject "\\overrightarrow{" "}
"]} then {
message "selection overrightarrowed"
} else {
message "enter text"
proc overleftarrow {} {
checkMathMode "overleftarrow" 1
if {[wrapObject "\\overleftarrow{" "}
"]} then {
message "selection overleftarrowed"
} else {
message "enter text"
proc stackrel {} {
checkMathMode "stackrel" 1
set currentPos [getPos]
if {[insertObject "\\stackrel{
"]} then {
goto $currentPos
nextTabStop
message "1st arg scriptstyle"
#--------------------------------------------------------------------------
# Spacing:
#--------------------------------------------------------------------------
proc negThin {} {checkMathMode "negThin" 1; insertObject "\\!"}
proc thin {} {checkMathMode "thin" 1; insertObject "\\,"}
proc medium {} {checkMathMode "medium" 1; insertObject "\\:"}
proc thick {} {checkMathMode "thick" 1; insertObject "\\;"}
proc quad {} {checkMathMode "quad" 1; insertObject "\\quad"}
proc qquad {} {checkMathMode "qquad" 1; insertObject "\\qquad"}
proc hspace {} {
checkMathMode "hspace" 1
if {[wrapObject "\\hspace{" "}
"]} then {
message "spacing set"
} else {
message "enter the desired horizontal spacing"
proc vspace {} {
checkMathMode "vspace" 1
if {[wrapObject "\\vspace{" "}
"]} then {
message "spacing set"
} else {
message "enter the desired horizontal spacing"
proc hfill {} {checkMathMode "hfill" 1; insertObject "\\hfill"}
proc vfill {} {checkMathMode "vfill" 1; insertObject "\\vfill"}
proc smallskip {} {checkMathMode "smallskip" 1; insertObject "\\smallskip"}
proc medskip {} {checkMathMode "medskip" 1; insertObject "\\medskip"}
proc bigskip {} {checkMathMode "bigskip" 1; insertObject "\\bigskip"}